import { http } from "@/utils/http";

// 获取图片地址返回类型
export interface ImagePath {
  url: string;
  full_url: string;
}

// 上传图片
export const uploadImage = (file: File) => {
  const formData = new FormData();
  formData.append("file", file);

  return http.request("post", "/api/common/upload", {
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data" // 覆盖全局 application/json
    }
    // 不手动设置Content-Type，让浏览器自动设置multipart/form-data和boundary
  });
};

// 获取广告列表
export const getAdvertisementList = (
  page = 1,
  limit = 10,
  exhibitor_id?: number
) => {
  return http.request("get", "/api/ad/list", {
    params: {
      page,
      limit,
      exhibitor_id
    }
  });
};

// 申请广告
export const applyAdvertisement = (data: any) => {
  return http.request("post", "/api/ad/apply", {
    data
  });
};

// 获取广告详情
export const getAdvertisementDetail = (id: number, exhibitor_id?: number) => {
  return http.request("get", "/api/ad/detail", {
    params: {
      id,
      exhibitor_id
    }
  });
};

// 更新广告
export const updateAdvertisement = (data: any) => {
  return http.request("post", "/api/ad/update", {
    data
  });
};

// 更改广告状态
export const updateAdvertisementStatus = (data: any) => {
  return http.request("post", "/api/ad/changeStatus", {
    data
  });
};
